<template>
  <el-dialog
    title="群发消息"
    width="600px"
    :visible.sync="visible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :show-close="false">
    <el-form :model="form" :rules="rules" ref="form">
      <el-form-item label="消息标题" prop="title">
        <el-input v-model="form.title" autocomplete="off" clearable></el-input>
      </el-form-item>
      <el-form-item label="消息内容" prop="content">
        <el-input type="textarea" v-model="form.content" :rows="5" autocomplete="off" clearable></el-input>
      </el-form-item>
      <el-form-item label="接收类型" prop="type" v-if="openType === '1'">
        <el-select v-model="form.type" style="width: 100%;" clearable>
          <el-option label="全部用户" value="1"></el-option>
          <el-option label="指定用户" value="0"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
  </el-dialog>
</template>

<script>
  export default {
    name: 'send-msg',
    props: {
      visible: {
        type: Boolean,
        default: false
      },
      /**
       * 1-群发
       * 0-私信
      */
      openType: {
        type: String,
        default: '1'
      }
    },
    data() {
      return {
        form: {
          title: '',
          content: '',
          type: this.openType,
          receiveUserIds: []
        },
        rules: {
          title: [
            { required: true, message: '请输入消息标题', trigger: 'blur' },
            { min: 1, max: 30, message: '最多30个字符', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '请输入消息内容', trigger: 'blur' },
            { min: 1, max: 200, message: '最多200个字符', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '请选择接收类型', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      // 取消
      cancel() {
        this.$emit('cancel', false)
      },
      // 提交
      submit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            this.$emit('submit', false, this.form)
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
